﻿
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using RBACProject.Application.Menu;
using RBACProject.Application.Menu.Dto;
using RBACProject.Domian;
using RBACProject.WebApi.Filter;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace RBACProject.WebApi.Controllers
{
    /// <summary>
    /// 菜单  Api接口控制器
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    //[Authorize]//权限锁
    //[AuthorizationFilterAttribute]//自定义授权过滤器
    public class MenuController : ControllerBase
    {
        private readonly IMenuService Imenu;

        public MenuController(IMenuService imenu)
        {
            Imenu = imenu;
        }

        ///// <summary>
        ///// 获取菜单子节点(递归)
        ///// </summary>
        ///// <param name="parentId"></param>
        ///// <returns></returns>
        //[HttpGet]
        //public IActionResult GetTreeInfo(int parentId)
        //{
        //    return Ok(Imenu.GetTreeInfo(parentId));
        //}


        /// <summary>
        /// 获取全部菜单 
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IActionResult GetMenuInfo()
        {
            return Ok(Imenu.GetMenuInfo());
        }

        /// <summary>
        /// 获取菜单类型枚举 （目录，菜单，按钮）
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IActionResult GetMenuTypeInfo()
        {
            return Ok(Imenu.GetMenuTypeInfo());
        }

        /// <summary>
        /// 菜单添加
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> AddMeunInfo(CreateUpdateDto dto)
        {
            return Ok(await Imenu.AddMeunInfo(dto));
        }

        /// <summary>
        /// 菜单逻辑删除
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpDelete]
        public async Task<IActionResult> DeleteMenu(int id)
        {
            return Ok(await Imenu.DeleteMenu(id));
        }

        /// <summary>
        /// 通过Id获取菜单一条数据
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> GetMenuInfoById(int id)
        {
            return Ok(await Imenu.GetMenuInfoById(id));
        }

        /// <summary>
        /// 菜单编辑
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<IActionResult> UpdateMenuInfo(MenuModel model)
        {
            return Ok(await Imenu.UpdateMenuInfo(model));
        }

        /// <summary>
        /// 根据登陆的用户角色获取可访问的菜单信息
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IActionResult GetMenuRoute()
        {
            return Ok(Imenu.GetMenuRoute());
        }
    }
}
